package com.groupfifteen.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.groupfifteen.dao.ExamrewrongquestionDao;
import com.groupfifteen.entity.ExamrewrongquestionEntity;
import com.groupfifteen.vo.ExamrewrongquestionVo;
import org.springframework.stereotype.Service;

@Service("examrewrongquestionService")
public class ExamrewrongquestionServiceImpl extends ServiceImpl<ExamrewrongquestionDao, ExamrewrongquestionEntity>
implements ExamrewrongquestionService{

    @Override
    public Integer AddExamrewrongquestion(ExamrewrongquestionEntity examrewrongquestionEntity) {

        return baseMapper.insert(examrewrongquestionEntity);
    }
    @Override
    public Integer DeleteExamrewrongquestion(Integer id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public ExamrewrongquestionEntity GetExamrewrongquestion(Integer id) {
        return baseMapper.selectById(id);
    }

    @Override
    public  Integer UpdateExamrewrongquestion(ExamrewrongquestionEntity examrewrongquestionEntity){
        return baseMapper.updateById(examrewrongquestionEntity);
    }

    @Override
    public IPage<ExamrewrongquestionEntity> Query(ExamrewrongquestionEntity examrewrongquestionEntity, int pageNo, int pageSize) {

        LambdaQueryWrapper<ExamrewrongquestionEntity> query = Wrappers.lambdaQuery();
        query.eq(examrewrongquestionEntity.getId() != null, ExamrewrongquestionEntity::getId, examrewrongquestionEntity.getId());

        if( pageNo == 0 )
        {
            pageNo = 1;
        }
        if( pageSize == 0 ){
            pageSize = 10;
        }

        IPage<ExamrewrongquestionEntity> page = Page.of(pageNo, pageSize);

        return baseMapper.selectPage(page, query);
    }

    @Override
    public IPage<ExamrewrongquestionEntity> Query(ExamrewrongquestionVo examrewrongquestionVo) {
//        LambdaQueryWrapper<SysUserEntity> query = Wrappers.lambdaQuery();
//        query.eq(sysUserVo.getId() != null, SysUserEntity::getId, sysUserVo.getId());
//
//
//        long pageNo = 1 , pageSize = 10;
//        IPage<SysUserEntity> page = Page.of(pageNo, pageSize);
//
//        return null;
        LambdaQueryWrapper<ExamrewrongquestionEntity> query = Wrappers.lambdaQuery();
        query.eq(examrewrongquestionVo.getId() != null, ExamrewrongquestionEntity::getId, examrewrongquestionVo.getId())
                .eq(examrewrongquestionVo.getYonghuId() != null, ExamrewrongquestionEntity::getYonghuId, examrewrongquestionVo.getYonghuId())
                .eq(examrewrongquestionVo.getExampaperId() != null, ExamrewrongquestionEntity::getExampaperId, examrewrongquestionVo.getExampaperId() );

        int currentPage = examrewrongquestionVo.getCurrentPage();
        int pageSize = examrewrongquestionVo.getPageSize();
        IPage<ExamrewrongquestionEntity> page = new Page<>(currentPage, pageSize);

        return baseMapper.selectPage(page, query);
    }

}
